package k8s

import (
	"context"

	appsv1 "k8s.io/api/apps/v1"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	core "k8s.io/client-go/kubernetes/typed/apps/v1"
)

func NewDaemonSet(c *kubernetes.Clientset) *DaemonSet {
	return &DaemonSet{
		core: c.AppsV1(),
	}
}

type DaemonSet struct {
	core core.AppsV1Interface
}

// 获取DaemonSet列表
func (s *DaemonSet) GetDaemonSets(ctx context.Context, namespace string, req *v1.ListOptions) (*appsv1.DaemonSetList, error) {
	return s.core.DaemonSets(namespace).List(ctx, *req)
}

// 获取DaemonSet详情
func (s *DaemonSet) GetDaemonSetDetails(ctx context.Context, namespace, name string) (*appsv1.DaemonSet, error) {
	return s.core.DaemonSets(namespace).Get(ctx, name, v1.GetOptions{})
}

// 创建DaemonSet
func (s *DaemonSet) CreateDaemonSet(ctx context.Context, namespace string, ds *appsv1.DaemonSet) (*appsv1.DaemonSet, error) {
	return s.core.DaemonSets(namespace).Create(ctx, ds, v1.CreateOptions{})
}

// 删除DaemonSet
func (s *DaemonSet) DeleteDaemonSet(ctx context.Context, namespace, name string) error {
	return s.core.DaemonSets(namespace).Delete(ctx, name, v1.DeleteOptions{})
}

// 更新DaemonSet
func (s *DaemonSet) UpdateDaemonSet(ctx context.Context, namespace string, ds *appsv1.DaemonSet) (*appsv1.DaemonSet, error) {
	return s.core.DaemonSets(namespace).Update(ctx, ds, v1.UpdateOptions{})
}
